package cn.big.bigd.biocode.dao;

import cn.big.bigd.biocode.model.VisitTrack;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.Date;

/**
 *@Author wangfan
 *@Date 2017/12/4 12:59
 */


@Repository
public interface VisitTrackDAO extends JpaRepository<VisitTrack, Long> {

    @Query("SELECT SUM(v.count) FROM VisitTrack v")
    Long downloadCount();


//    @Query("SELECT SUM(v.count) FROM VisitTrack v where v.targetId = ?1")
//    Integer downloadToolCount(int id);


    VisitTrack findByDateAndCountryAndTargetTypeAndTargetId(Date date,String c,String t,Integer tId);

    @Query(value = "SELECT SUM(v.count) FROM  tools t INNER  JOIN  releases r ON t.id=r.tool_id\n" +
            "  INNER  JOIN visit_tracks v ON r.id=v.target_id WHERE  t.id  = ?1",nativeQuery = true)
    Integer toolDownloadCount(int toolId);


    @Query("SELECT SUM(v.count) FROM VisitTrack v where v.targetId = ?1")
    Integer releaseDownloadCount(int releaseId);

}
